const {ccclass, property} = cc._decorator;

@ccclass
export default class CameraHelper extends cc.Component {

    @property(cc.Node)
    camera: cc.Node = null;

    moveBy(deltaY)
    {
        var me = this;
        cc.tween(this.camera).by(1, {y: deltaY}, { easing: 'backOut'})
        .call(() => { 
            cc.log("tween finish: now y:" + me.camera.y);
        })  
        .start();
    }

    moveTo(posY)
    {
        this.camera.y = posY;
    }

    onKeyDown (event:cc.Event.EventKeyboard) {
        cc.log("onKeyDown:" + event.keyCode);
        switch(event.keyCode) {
            case cc.macro.KEY.w:
                this.moveBy(100);
                break;
            case cc.macro.KEY.s:
                this.moveBy(-100);
                break;
        }
    }

    onKeyUp (event) {
        cc.log("onKeyUp:" + event.keyCode);
    }

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
    }


    start () {

    }

    // update (dt) {}
}
